package com.jfok.server.controller;

import java.util.List;
import javax.annotation.Resource;
import net.sf.json.JSONArray;
import net.sf.json.JSONSerializer;
import net.sf.json.JsonConfig;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jfok.server.hibernate.system._ModuleGroup;
import com.jfok.server.service.RoleService;
import com.jfok.shared.RolePopedom;

@Controller
@RequestMapping("/role")

public class RoleController {

	
	@Resource
	private RoleService roleService;

	@RequestMapping("/getrolepopedoms.do")
	public @ResponseBody
	List<_ModuleGroup> getRolePopedoms(String roleId) {
		return roleService.getRolePopedoms(roleId);
	}


	@RequestMapping("/getuserpopedoms.do")
	public @ResponseBody
	List<_ModuleGroup> getUserPopedoms(Integer userId) {
		return roleService.getUserPopedoms(userId);
	}

	
	@RequestMapping("/saverolepopedoms.do")
	public @ResponseBody
	Boolean setRolePopedoms(String roleId, String formdata, String additionids) {
		JsonConfig config = new JsonConfig();
		config.setArrayMode(JsonConfig.MODE_OBJECT_ARRAY);
		config.setRootClass(RolePopedom.class);
		RolePopedom rolePopedoms[] = (RolePopedom[]) JSONSerializer.toJava(
				JSONArray.fromObject(formdata), config);
		return roleService.setRolePopedoms(roleId, rolePopedoms, additionids);

	}

}
